import 'package:flutter/material.dart';

import '../../../jm_flutter.dart';
import '../../common/common.dart';

class AppLanguagePage extends StatefulWidget {
  const AppLanguagePage({Key? key}) : super(key: key);

  @override
  _AppLanguagePageState createState() => _AppLanguagePageState();
}

class _AppLanguagePageState extends State<AppLanguagePage> {
  @override
  Widget build(BuildContext context) {
    return MyScaffold(
      title: "显示语言".i18n,
      body: SafeArea(
        child: ListView.builder(
          itemCount: I18n.languages.length,
          itemBuilder: (BuildContext context, int index) {
            AppLanguage appLanguage = I18n.languages[index];
            return MyItem(
              title: index == 0 ? appLanguage.name.i18n : appLanguage.name,
              type: MyItemType.options,
              isOn: I18n.languageCode == appLanguage.code,
              onTap: () {
                setState(() {
                  I18n.setLanguage(appLanguage);
                });
              },
            );
          },
        ),
      ),
    );
  }
}
